using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE
{
      public class RpgModelShadowController : MonoBehaviour
      {
          public Color color = new Color(0,0,0,0.75f);
          public float offsetX = -0.68f;
          public float offsetY = 0.56f;
          public float offsetZ;
          public float offsetW;
          public float height = 0.01f;
#if UNITY_EDITOR
   
          void Update()
          {
              if (PveGlobalVlues.ModelShadowEditor)
              {
                  var units = UnitManager.Instance.units;
                  for (int i = 0; i < units.Count; i++)
                  {
                      var skinned = units[i].gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
                      for (int j = 0; j < skinned.Length; j++)
                      {
                          var mats = skinned[j].materials;
                          for (int k = 0; k < mats.Length; k++)
                          {
                              var mat = mats[k];
                              if (mat.shader.name.Contains("Shadow"))
                              {
                                  mat.SetColor("_ShadowColor",color);
                                  mat.SetVector("_ShadowOffset",new Vector4(offsetX,offsetY,offsetZ,offsetW));
                                  mat.SetFloat("_ShadowHeight",height);
                              }
                          }
                      }
                      var meshed = units[i].gameObject.GetComponentsInChildren<MeshRenderer>();
                      for (int j = 0; j < meshed.Length; j++)
                      {
                          var mats = meshed[j].materials;
                          for (int k = 0; k < mats.Length; k++)
                          {
                              var mat = mats[k];
                              if (mat.shader.name.Contains("Shadow"))
                              {
                                  mat.SetColor("_ShadowColor",color);
                                  mat.SetVector("_ShadowOffset",new Vector4(offsetX,offsetY,offsetZ,offsetW));
                                  mat.SetFloat("_ShadowHeight",height);
                              }
                          }
                      }
                  }
              }
            
          }
#endif

      }
}